package net.stogi.dsper.ui.client.module.user;

import java.util.HashMap;
import java.util.Map;

import net.stogi.common.gwt.dispatch.client.core.ActionManager;
import net.stogi.common.gwt.frame.client.core.EventBus;
import net.stogi.common.gwt.frame.client.module.Module;
import net.stogi.common.gwt.frame.client.mvp.AbstractPresenter;

import com.google.gwt.user.client.ui.Widget;

public class UserModule implements Module {

	public static final String USER_PROFILE_EDITOR_PRESENTER = "user-profile-editor-presenter";

	public static final String USER_PROFILE_EDITOR_WIDGET = "user-profile-editor-widget";

	public static final String USER_PROFILE_LIST_PRESENTER = "user-profile-list-presenter";

	public static final String USER_PROFILE_LIST_WIDGET = "user-profile-list-widget";

	private ActionManager actionManager;

	private EventBus eventBus;

	private Map<String, AbstractPresenter> presenterMap = new HashMap<String, AbstractPresenter>();

	private Map<String, Widget> widgetMap = new HashMap<String, Widget>();

	protected UserModule(ActionManager actionManager, EventBus eventBus) {
		this.actionManager = actionManager;
		this.eventBus = eventBus;
		initModule();
	}

	@Override
	public Widget getWidget(String name) {
		return widgetMap.get(name);
	}

	protected void initModule() {
		UserProfileEditorWidget userProfileEditorWidget = new UserProfileEditorWidget();
		UserProfileEditorPresenter userProfileEditorPresenter = new UserProfileEditorPresenter(userProfileEditorWidget,
				actionManager, eventBus);
		UserProfileListWidget userProfileListWidget = new UserProfileListWidget();
		UserProfileListPresenter userProfileListPresenter = new UserProfileListPresenter(userProfileListWidget, actionManager,
				eventBus);
		widgetMap.put(USER_PROFILE_EDITOR_WIDGET, userProfileEditorWidget);
		presenterMap.put(USER_PROFILE_EDITOR_PRESENTER, userProfileEditorPresenter);
		widgetMap.put(USER_PROFILE_LIST_WIDGET, userProfileListWidget);
		presenterMap.put(USER_PROFILE_LIST_PRESENTER, userProfileListPresenter);
	}
}
